/*     */ package com.openbravo.pos.forms;
/*     */ 
/*     */ import java.io.File;
/*     */ import java.io.FileInputStream;
/*     */ import java.io.FileOutputStream;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.io.OutputStream;
/*     */ import java.net.InetAddress;
/*     */ import java.net.UnknownHostException;
/*     */ import java.util.Locale;
/*     */ import java.util.Properties;
/*     */ import java.util.logging.Logger;
/*     */ 
/*     */ public class AppConfig
/*     */   implements AppProperties
/*     */ {
/*  38 */   private static Logger logger = Logger.getLogger("com.openbravo.pos.forms.AppConfig");
/*     */   private Properties m_propsconfig;
/*     */   private File configfile;
/*     */ 
/*     */   public AppConfig(String[] args)
/*     */   {
/*  44 */     if (args.length == 0)
/*  45 */       init(getDefaultConfig());
/*     */     else
/*  47 */       init(new File(args[0]));
/*     */   }
/*     */ 
/*     */   public AppConfig(File configfile)
/*     */   {
/*  52 */     init(configfile);
/*     */   }
/*     */ 
/*     */   private void init(File configfile) {
/*  56 */     this.configfile = configfile;
/*  57 */     this.m_propsconfig = new Properties();
/*     */ 
/*  59 */     logger.info("Reading configuration file: " + configfile.getAbsolutePath());
/*     */   }
/*     */ 
/*     */   private File getDefaultConfig() {
/*  63 */     return new File(new File(System.getProperty("user.home")), "powerfulpos.properties");
/*     */   }
/*     */ 
/*     */   public String getProperty(String sKey) {
/*  67 */     return this.m_propsconfig.getProperty(sKey);
/*     */   }
/*     */ 
/*     */   public String getHost() {
/*  71 */     return getProperty("machine.hostname");
/*     */   }
/*     */ 
/*     */   public File getConfigFile() {
/*  75 */     return this.configfile;
/*     */   }
/*     */ 
/*     */   public void setProperty(String sKey, String sValue) {
/*  79 */     if (sValue == null)
/*  80 */       this.m_propsconfig.remove(sKey);
/*     */     else
/*  82 */       this.m_propsconfig.setProperty(sKey, sValue);
/*     */   }
/*     */ 
/*     */   private String getLocalHostName()
/*     */   {
/*     */     try {
/*  88 */       return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException eUH) {
/*     */     }
/*  90 */     return "localhost";
/*     */   }
/*     */ 
/*     */   public boolean delete()
/*     */   {
/*  95 */     loadDefault();
/*  96 */     return this.configfile.delete();
/*     */   }
/*     */ 
/*     */   public void load()
/*     */   {
/* 101 */     loadDefault();
/*     */     try
/*     */     {
/* 104 */       InputStream in = new FileInputStream(this.configfile);
/* 105 */       if (in != null) {
/* 106 */         this.m_propsconfig.load(in);
/* 107 */         in.close();
/*     */       }
/*     */     } catch (IOException e) {
/* 110 */       loadDefault();
/*     */     }
/*     */   }
/*     */ 
/*     */   public void save()
/*     */     throws IOException
/*     */   {
/* 117 */     OutputStream out = new FileOutputStream(this.configfile);
/* 118 */     if (out != null) {
/* 119 */       this.m_propsconfig.store(out, "PFPOS. Configuration file.");
/* 120 */       out.close();
/*     */     }
/*     */   }
/*     */ 
/*     */   private void loadDefault()
/*     */   {
/* 126 */     this.m_propsconfig = new Properties();
/*     */ 
/* 128 */     String dirname = System.getProperty("dirname.path");
/* 129 */     dirname = dirname == null ? "./" : dirname;
/*     */ 
/* 131 */     this.m_propsconfig.setProperty("db.driverlib", new File(new File(dirname), "lib/derby.jar").getAbsolutePath());
/* 132 */     this.m_propsconfig.setProperty("db.driver", "org.apache.derby.jdbc.EmbeddedDriver");
/* 133 */     this.m_propsconfig.setProperty("db.URL", "jdbc:derby:" + new File(new File(System.getProperty("user.home")), "powerfulpos-database").getAbsolutePath() + ";create=true");
/* 134 */     this.m_propsconfig.setProperty("db.user", "");
/* 135 */     this.m_propsconfig.setProperty("db.password", "");
/*     */ 
/* 153 */     this.m_propsconfig.setProperty("machine.hostname", getLocalHostName());
/*     */ 
/* 155 */     Locale l = Locale.getDefault();
/* 156 */     this.m_propsconfig.setProperty("user.language", l.getLanguage());
/* 157 */     this.m_propsconfig.setProperty("user.country", l.getCountry());
/* 158 */     this.m_propsconfig.setProperty("user.variant", l.getVariant());
/*     */ 
/* 160 */     this.m_propsconfig.setProperty("swing.defaultlaf", System.getProperty("swing.defaultlaf", "javax.swing.plaf.metal.MetalLookAndFeel"));
/*     */ 
/* 162 */     this.m_propsconfig.setProperty("machine.printer", "screen");
/* 163 */     this.m_propsconfig.setProperty("machine.printer.2", "Not defined");
/* 164 */     this.m_propsconfig.setProperty("machine.printer.3", "Not defined");
/* 165 */     this.m_propsconfig.setProperty("machine.display", "screen");
/* 166 */     this.m_propsconfig.setProperty("machine.scale", "Not defined");
/* 167 */     this.m_propsconfig.setProperty("machine.screenmode", "window");
/* 168 */     this.m_propsconfig.setProperty("machine.ticketsbag", "standard");
/* 169 */     this.m_propsconfig.setProperty("machine.scanner", "Not defined");
/*     */ 
/* 171 */     this.m_propsconfig.setProperty("payment.gateway", "external");
/* 172 */     this.m_propsconfig.setProperty("payment.magcardreader", "Not defined");
/* 173 */     this.m_propsconfig.setProperty("payment.testmode", "false");
/* 174 */     this.m_propsconfig.setProperty("payment.commerceid", "");
/* 175 */     this.m_propsconfig.setProperty("payment.commercepassword", "password");
/*     */ 
/* 177 */     this.m_propsconfig.setProperty("machine.printername", "(Default)");
/*     */ 
/* 180 */     this.m_propsconfig.setProperty("paper.receipt.x", "10");
/* 181 */     this.m_propsconfig.setProperty("paper.receipt.y", "287");
/* 182 */     this.m_propsconfig.setProperty("paper.receipt.width", "190");
/* 183 */     this.m_propsconfig.setProperty("paper.receipt.height", "546");
/* 184 */     this.m_propsconfig.setProperty("paper.receipt.mediasizename", "A4");
/*     */ 
/* 187 */     this.m_propsconfig.setProperty("paper.standard.x", "72");
/* 188 */     this.m_propsconfig.setProperty("paper.standard.y", "72");
/* 189 */     this.m_propsconfig.setProperty("paper.standard.width", "451");
/* 190 */     this.m_propsconfig.setProperty("paper.standard.height", "698");
/* 191 */     this.m_propsconfig.setProperty("paper.standard.mediasizename", "A4");
/*     */ 
/* 193 */     this.m_propsconfig.setProperty("machine.uniqueinstance", "false");
/*     */   }
/*     */ }

/* Location:           D:\PowerFulPOS-2.30.2\openbravopos.jar
 * Qualified Name:     com.openbravo.pos.forms.AppConfig
 * JD-Core Version:    0.6.0
 */